$(function () {
    //初始化专业搜索条件
    $.initSubject({
        element:'subject-box',
        confirmBtn:false,
        removeBtn: false,
        style:false,
        notMultiple:true,
        classText:'form-control mb10',
        width:100,
        selectCallback:function(subjectIds){
            $("#subjectIds").val(subjectIds);
        }
    });
    listCount('LIVE');
    //加载课程数据
    listLiveCourse(1);
    $("body").on('click', '#btn1,#btn2', function () { //搜索课程
        listLiveCourse(1);
    }).on('click','#copy-course',function () {//复制课程
        var courseId = $(this).data('id');
        copyCourse(courseId,function () {
            window.location.href = baseloaction +'/admin/course/live/liveList';
        });
    }).on("click",".share-to-user",function () {
        var courseId = $(this).data("id");
        shareAddressFn(courseId,"LIVE");
    })
});

//加载课程数据
function listLiveCourse(page) {
    var params = $("#search-form").serializeJSON();
    params = JSON.stringify(params);
    var obj = {
        url: baseloaction + '/admin/course/live/ajaxLiveCourseList',//请求URL
        contextId: 'course-list-context',//响应内容页面设置内容ID
        params: params,//请求参数
        pageNo: page,//页码
        pageCall: listLiveCourse, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
        selectAllId: 'all-course', //全选框ID
        callback: function () {//数据加载完成回调
            lazyCourseImage();
        }
    };
    ajaxGetListData(obj);
}

function shareAddressFn(id,type) {
    parent.layer.open({
        type: 2,
        area: ['320px', '420px'],
        skin: 'layui-layer-demo',
        title: '分享地址',
        btn:false,
        content: [`${baseloaction}/admin/course/cou/shareCourseToUser?courseId=${id}&type=${type}`,'no']
    })
}